﻿
@{
    ViewBag.Title = "TemplateIndex";
    Layout = "~/Views/Shared/_MyLayout.cshtml";
}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>项目流程信息</legend>
</fieldset>
<div>
    <form class="layui-form" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">项目选择</label>
            <div class="layui-input-inline" style="width:500px;">
                <select name="ProjectId" lay-verify="required" lay-search lay-filter="ProjectSelFilter" id="ProjectSel">
                    <option value=""></option>
                    @for (int i = 0; i < ViewBag.ProjectList.Count; i++)
                    {
                        <option value="@ViewBag.ProjectList[i]["ProjectId"]">@ViewBag.ProjectList[i]["Name"]|@ViewBag.ProjectList[i]["ProjectCode"]|@ViewBag.ProjectList[i]["Type"]</option>
                    }
                </select>
            </div>
            <button type="button" class="layui-btn" style="float:left;" id="BtnAdd"><i class="layui-icon">&#xe61f;</i>新增</button>
            @*<button type="button" class="layui-btn layui-btn-danger" style="float:left;" id="BtnQuoteAdd"><i class="layui-icon">&#xe61f;</i>引入模板</button>*@
            <label class="layui-form-label" style="width:50px;">状态</label>
            <div class="layui-input-inline" style="width:100px;">
                <select id="StateSel" lay-filter="StateSelFilter">
                    <option value="全部">全部</option>
                    <option value="进行中">进行中</option>
                    <option value="已完成">已完成</option>
                    <option value="滞后">滞后</option>
                </select>
            </div>
            <label class="layui-form-label" style="width:50px;">阶段</label>
            <div class="layui-input-inline" style="width:100px;">
                <select id="StateSel" lay-filter="StageSelFilter">
                    <option value="0">全部</option>
                    <option value="1">项目前期</option>
                    <option value="2">前期测算</option>
                    <option value="3">项目实施</option>
                    <option value="4">竣工结算</option>
                    <option value="5">决算收款</option>
                </select>
            </div>
        </div>
    </form>
</div>

<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15" id="InfoContent">
        @for (int i = 0; i < 0; i++)
        {
            <div class="layui-col-md3">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <div style="float:left;width:85%;font-size:16px;">
                            节点名
                        </div>
                        <div style="float:left;width:15%;font-size:16px;">
                            序号
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <div style="font-size:14px;height:auto;height:20px;">
                            <div style="float:left;width:50%;">
                                部门：业务部
                            </div>
                            <div style="float:left;width:50%;">
                                负责人：张三
                            </div>
                        </div>
                        <div style="height:30px;margin-top:5px;">
                            <div style="float:left;width:90%">
                                截止时间：2019-12-20
                            </div>
                            <div style="float:left;width:10%">
                                @*<i class="layui-icon layui-icon-ok-circle" style="font-size:30px; color:#32CD32;"></i>*@
                                @*<i class="layui-icon layui-icon-close-fill" style="font-size:30px; color:#FF4500;"></i>*@
                                <i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop" style="font-size:30px; color:#00BFFF;"></i>
                                
                            </div>
                        </div>
                        <div style="height:20px;">
                            最近更新：2019-12-20
                        </div>
                    </div>
                </div>
            </div>
        }


        @*<div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">标题</div>
                <div class="layui-card-body">
                    内容
                </div>
            </div>
        </div>*@
    </div>
</div>

<div id="AddLayer" style="display:none;">
    <form class="layui-form" id="AddFrom" style="margin-top:10px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">节点名</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" name="NodeName" value="" placeholder="必填" required lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">序号</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="NodeNum" value="" placeholder="必填" required lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">截止时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="EndTime" value="" id="AddEndTime" required lay-verify="required" placeholder="请输选择时间" autocomplete="off" class="layui-input">
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工作内容</label>
            <div class="layui-input-block" style="width:800px;">
                <textarea name="Content" placeholder="请输入工作内容" class="layui-textarea" required lay-verify="required"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门选择</label>
            <div class="layui-input-inline" style="width:120px;">
                <select name="Department" required lay-verify="required" lay-filter="AddDepartmentSelFilter">
                    <option value="工程部" selected>工程部</option>
                    <option value="业务部">业务部</option>
                    <option value="行政部">行政部</option>
                    <option value="技经部">技经部</option>
                    <option value="市场部">市场部</option>
                    <option value="财务部">财务部</option>
                </select>
            </div>
            <label class="layui-form-label">负责人</label>
            <div class="layui-input-inline" style="width:120px;">
                <select name="UserId" required lay-verify="required" lay-filter="AddUserIdSelFilter">
                    @for (int i = 0; i < ViewBag.UserList.Count; i++)
                    {
                        <option value="@ViewBag.UserList[i]["UserId"]">@ViewBag.UserList[i]["UserName"]</option>
                    }
                </select>
            </div>
            <label class="layui-form-label">项目阶段</label>
            <div class="layui-input-inline" style="width:120px;">
                <select name="ProStage" required lay-verify="required" lay-filter="AddProStageSelFilter">
                    <option value="1">项目前期</option>
                    <option value="2">前期测算</option>
                    <option value="3">项目实施</option>
                    <option value="4">竣工结算</option>
                    <option value="5">决算收款</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"></label>
            </div>
            <button type="button" class="layui-btn" id="BtnAddFromSave">保存</button>
        </div>
        <button type="submit" id="formAddsubmit" class="layui-btn" lay-submit lay-filter="formAddVerify" style="display:none;">立即提交</button>
    </form>
</div>


<div id="EditLayer" style="display:none;">
    <form class="layui-form" id="EditFrom" style="margin-top:10px;">
        <input type="text" name="ProcessId" value="" style="display:none;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">节点名</label>
                <div class="layui-input-inline" style="width:200px;">
                    <input type="text" name="NodeName" value="" placeholder="必填" required lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">序号</label>
                <div class="layui-input-inline" style="width:100px;">
                    <input type="number" name="NodeNum" value="" placeholder="必填" required lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">截止时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="EndTime" value="" id="EditEndTime" required lay-verify="required" placeholder="请输选择时间" autocomplete="off" class="layui-input">
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工作内容</label>
            <div class="layui-input-block" style="width:800px;">
                <textarea name="Content" placeholder="请输入工作内容" class="layui-textarea" required lay-verify="required"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">部门选择</label>
            <div class="layui-input-inline" style="width:120px;">
                <select name="Department" id="EditDepartment" required lay-verify="required" lay-filter="EditDepartmentSelFilter">
                    <option value="工程部">工程部</option>
                    <option value="业务部">业务部</option>
                    <option value="行政部">行政部</option>
                    <option value="技经部">技经部</option>
                    <option value="市场部">市场部</option>
                    <option value="财务部">财务部</option>
                </select>
            </div>
            <label class="layui-form-label">负责人</label>
            <div class="layui-input-inline" style="width:120px;">
                <select name="UserId" id="EditUserId" required lay-verify="required" lay-filter="EditUserIdSelFilter">
                    @for (int i = 0; i < ViewBag.UserList.Count; i++)
                    {
                        <option value="@ViewBag.UserList[i]["UserId"]">@ViewBag.UserList[i]["UserName"]</option>
                    }
                </select>
            </div>
            <label class="layui-form-label">状态修改</label>
            <div class="layui-input-inline" style="width:120px;">
                <select name="NodeState" id="EditNodeState" required lay-verify="required" lay-filter="EditNodeStateSelFilter">
                    <option value="进行中">进行中</option>
                    <option value="滞后">滞后</option>
                    <option value="已完成">已完成</option>
                </select>
            </div>
            @*<div class="layui-inline">
                <label class="layui-form-label"></label>
            </div>*@
            <button type="button" class="layui-btn" id="BtnEditFromSave">更新</button>
            <button type="button" class="layui-btn layui-btn-danger" id="BtnEditFromDel">删除</button>
        </div>

        <button type="submit" id="formEditsubmit" class="layui-btn" lay-submit lay-filter="formEditVerify" style="display:none;">立即提交</button>
    </form>
    <hr>

    <form class="layui-form" style="margin-top:5px;">
        <div class="layui-form-item">
            <label class="layui-form-label">操作</label>
            <button type="button" class="layui-btn" style="float:left;margin-left:5px;" id="BtnOpenLogLayer">添加记录</button>
            <label class="layui-form-label"></label>
            <button type="button" class="layui-btn  layui-btn-normal" style="float:left;margin-left:5px;" id="BtnRequestDone">申请完结</button>
        </div>
    </form>
    <hr />
    <div id="LogContent" style="width:100%;height:auto">
        <div>
            <div style="margin-left:10px;"><span style="margin-right:10px;">添加记录</span>2019-01-03</div>
            <blockquote class="layui-elem-quote" style="padding:5px;">引用区的文字</blockquote>
        </div>
    </div>

</div>




<div id="LogAddLayer" style="display:none;">
    <form class="layui-form" id="LogAddFrom" style="margin-top:10px;">
        <div class="layui-form-item">
            <label class="layui-form-label">日志记录</label>
            <div class="layui-input-block">
                <textarea name="Content" placeholder="请输入记录日志" class="layui-textarea" id="LogTextarea" required lay-verify="required"></textarea>
                <button type="button" class="layui-btn " id="BtnLogTextAdd">保存</button>
            </div>
        </div>

    </form>
</div>




<div id="AddTemplateLayer" style="display:none;">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" name="StartTime" value="" id="TemplateStartTime" required lay-verify="required" placeholder="请输选择时间" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">截止时间</label>
            <div class="layui-input-inline">
                <input type="text" name="EndTime" value="" id="TemplateEndTime" required lay-verify="required" placeholder="请输选择时间" autocomplete="off" class="layui-input">
            </div>
            <button type="button" class="layui-btn layui-btn-danger" style="float:left;" id="BtnQuoteSave">确认新增</button>
        </div>
    </form>
    <table id="QuoteTable" lay-filter="QuoteTableFilter1"></table>
</div>



<script type="text/javascript">

    var UserId = "@ViewBag.UserId";
    var AuthList = JSON.parse('@Html.Raw(Json.Encode(ViewBag.AuthList))');
    function SearchAuth(Type,Name) {
        var IsGet = false;
        for (var i = 0; i < AuthList.length; i++) {
            if (AuthList[i].Type == Type && AuthList[i].Name == Name) {
                IsGet = true;
            }
        }
        return IsGet;
    }
    var layerindex;
    var layerindex_Log;
    var NodeObjBefore = {};
    layui.use(['form', 'table', 'upload', 'layer', 'element', 'laydate'], function () {
        var element = layui.element;
        var layer = layui.layer;
        var table = layui.table;
        var tab = parent.tab;
        var form = layui.form;
        var laydate = layui.laydate;
        //layerindex;
        var IsValidate = 0;
        var ProjectId = "";
        var StateSel = "全部";
        var ProStageSel = 0;
        var ApplicationState = "";

        //拦截form提交消息
        form.on('submit(formAddVerify)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            IsValidate = 1;
            return false;
        });
        form.on('submit(formEditVerify)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            IsValidate = 1;
            return false;
        });

        laydate.render({
            elem: '#AddEndTime' //指定元素
        });

        laydate.render({
            elem: '#EditEndTime'
        });

        laydate.render({
            elem: '#TemplateStartTime'
        });

        laydate.render({
            elem: '#TemplateEndTime'
        });

        //监听折叠
        element.on('collapse(test)', function (data) {
            layer.msg('展开状态：' + data.show);
        });


        form.on('select(ProjectSelFilter)', function (data) {
            //console.log(data.elem); //得到select原始DOM对象
            //console.log(data.value); //得到被选中的值
            //console.log(data.othis); //得到美化后的DOM对象

            ProjectId = data.value;
            $("#InfoContent").empty();
            if (data.value == "") {
                ProjectId = "";
                return;
            }
            ReflushContent(ProjectId, StateSel);

        });

        //监听状态下拉
        form.on('select(StateSelFilter)', function (data) {
            StateSel = data.value;
            //判断项目选择是否为空
            if (ProjectId == "") {
                return;
            }
            ReflushContent(ProjectId, StateSel);
        });

        //监听状态下拉
        form.on('select(StageSelFilter)', function (data) {
            ProStageSel = data.value;
            //判断项目选择是否为空
            if (ProjectId == "") {
                return;
            }
            ReflushContent(ProjectId, StateSel, ProStageSel);
        });



        //刷新内容  这里使用默认参数
        function ReflushContent(ProjectId, State ,ProStage) {
            $("#InfoContent").empty();
            ProStage = ProStage || "0";
            $.ajax({
                type: "POST",
                url: "/Process/GetProcess",
                async: false,
                data: { "ProjectId": ProjectId, "State": State, "ProStage": ProStage },
                success: function (msg) {
                    if (msg.length > 0) {

                        var str = "";
                        var NodeState = "";

                        for (var i = 0; i < msg.length; i++) {
                            if (msg[i].NodeState == "进行中") {
                                NodeState = '<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop" style="font-size:30px; color:#00BFFF;"></i>';
                            }
                            else if (msg[i].NodeState == "已完成") {
                                NodeState = '<i class="layui-icon layui-icon-ok-circle" style="font-size:30px; color:#32CD32;"></i>';
                            }
                            else if (msg[i].NodeState == "滞后") {
                                NodeState = '<i class="layui-icon layui-icon-close-fill" style="font-size:30px; color:#FF4500;"></i>';
                            }
                            str = "";
                            str += '<div class="layui-col-md3">' +
                                '<div class="layui-card">';
                            if (msg[i].ApplicationState == 1) {
                                str += '<div class="layui-card-header" style="background-color:dodgerblue;">';
                            }
                            else {
                                str += '<div class="layui-card-header">';
                            }

                            str += '<div style="float:left;width:85%;font-size:16px;">' +
                                '' + msg[i].NodeName +
                                '</div>' +
                                '<div style="float:left;width:15%;font-size:16px;">' +
                                '' + msg[i].NodeNum +
                                '</div>' +
                                '</div>' +
                                '<div class="layui-card-body ClickEvent" ProcessId="' + msg[i].ProcessId + '"  style="cursor:pointer;">' +
                                '<div style="font-size:14px;height:auto;height:20px;">' +
                                '<div style="float:left;width:50%;">' +
                                '部门：' + msg[i].Department +
                                '</div>' +
                                '<div style="float:left;width:50%;">' +
                                '负责人：' + msg[i].UserName +
                                '</div>' +
                                '</div>' +
                                '<div style="height:30px;margin-top:5px;">' +
                                '<div style="float:left;width:90%">' +
                                '截止时间：' + msg[i].EndTime +
                                '</div>' +
                                '<div style="float:left;width:10%">' +
                                NodeState +
                                '</div>' +
                                '</div>' +
                                '<div style="height:20px;">' +
                                '最近更新：' + msg[i].UpdateTime +
                                '</div>' +
                                '</div>' +
                                '</div>' +
                                '</div>' +
                                '';
                            $("#InfoContent").append(str);
                        }
                    }
                }
            });


        }

        //打开一个节点
        $(document).on("click", ".ClickEvent", function () {
            var ProcessId = $(this).attr("ProcessId");
            $.ajax({
                type: "POST",
                url: "/Process/GetProcessById",
                async: false,
                data: { "ProcessId": ProcessId },
                success: function (msg) {
                    var ProStageName = "";
                    ProStageName = ProStageTrans(msg.ProStage);
                    layerindex = layer.open({
                        type: 1,
                        title: ['编辑-项目阶段（' + ProStageName+')', 'font-size:18px;'],
                        area: ['920px', '600px'],
                        content: $("#EditLayer"),  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                        success: function (layero, index) {
                            $("#EditFrom input[name='ProcessId']").val(ProcessId);
                            $("#EditFrom input[name='NodeName']").val(msg.NodeName);
                            $("#EditFrom input[name='NodeNum']").val(msg.NodeNum);
                            $("#EditFrom input[name='EndTime']").val(msg.EndTime);
                            $("#EditFrom textarea[name='Content']").val(msg.Content);
                            $("#EditDepartment").val(msg.Department);
                            $("#EditUserId").val(msg.UserId);
                            $("#EditNodeState").val(msg.NodeState);
                            form.render();
                            //这里保留打开的节点信息
                            NodeObjBefore = msg;
                            ReflushLog(ProcessId);
                            //下面刷新申请按钮
                            ApplicationState = msg.ApplicationState;
                            if (ApplicationState == 1) {
                                $("#BtnRequestDone").text("驳回申请");
                            }
                            else {
                                $("#BtnRequestDone").text("申请完结");
                            }

                        }
                    });
                }
            });

        })



        $("#BtnAdd").on("click", function () {
            //先判断权限 节点管理
            if (false == SearchAuth("ProcessAuth", "节点管理")) {
                alert("没有权限");
                return;
            }
            if (ProjectId == "") { return; }
            layerindex = layer.open({
                type: 1,
                title: ['新增', 'font-size:18px;'],
                area: ['920px', '600px'],
                content: $("#AddLayer"),  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                success: function (layero, index) {
                    //$("#AddFrom input[name='TestFeeId']").val("");
                    //$("#Type").find("option[value='" + TypeName + "']").attr("selected", true);
                    //form.render();
                }
            });
        });

        $("#BtnQuoteAdd").on("click", function () {
            //先判断权限 节点管理
            if (false == SearchAuth("ProcessAuth", "节点管理")) {
                alert("没有权限");
                return;
            }
            if (ProjectId == "") { return; }
            layerindex = layer.open({
                type: 1,
                title: ['新增', 'font-size:18px;'],
                area: ['800px', '600px'],
                content: $("#AddTemplateLayer"),  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                success: function (layero, index) {
                    //$("#AddFrom input[name='TestFeeId']").val("");
                    //$("#Type").find("option[value='" + TypeName + "']").attr("selected", true);
                    //form.render();
                }
            });
        });




        $("#BtnAddFromSave").on("click", function () {

            $("#formAddsubmit").click();
            if (IsValidate == 1) {
                IsValidate = 0;
            } else {
                return;
            }
            var obj = $("#AddFrom").serializeArray();
            var data = {};
            $.each(obj, function (i, v) {
                data[v.name] = v.value;
            });
            data["ProjectId"] = ProjectId;
            data["UserName"] = $("#AddFrom select[name='UserId']").find("option:selected").text();
            data["NodeState"] = "进行中";
            data["IsDelete"] = 0;
            $.ajax({
                type: "POST",
                url: "/Process/ProcessAdd",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        layer.close(layerindex);
                        ReflushContent(ProjectId, StateSel);
                    } else {
                        alert(msg.result);
                    }
                }
            });

        });

        $("#BtnEditFromSave").on("click", function () {
            //先判断权限
            if (false == SearchAuth("ProcessAuth", NodeObjBefore.Department)) {
                alert("没有权限");
                return;
            }


            $("#formEditsubmit").click();
            if (IsValidate == 1) {
                IsValidate = 0;
            } else {
                return;
            }
            var obj = $("#EditFrom").serializeArray();
            var data = {};
            $.each(obj, function (i, v) {
                data[v.name] = v.value;
            });
            data["UserName"] = $("#EditFrom select[name='UserId']").find("option:selected").text();
            //下面统计变更内容
            var TempStr = "";
            var LogType = "";   //这里为空，就说明没有任何变更

            //以下为内容变更
            if (data["NodeName"] != NodeObjBefore.NodeName) {
                TempStr += "变更节点名为：" + data["NodeName"] + "；";
                LogType = "内容变更";
            }
            if (data["NodeNum"] != NodeObjBefore.NodeNum) {
                TempStr += "变更序号为：" + data["NodeNum"] + "；";
                LogType = "内容变更";
            }
            if (data["EndTime"] != NodeObjBefore.EndTime) {
                TempStr += "变更结束时间为：" + data["EndTime"] + "；";
                LogType = "内容变更";
            }
            if (data["Content"] != NodeObjBefore.Content) {
                TempStr += "变更工作内容为：" + data["Content"] + "；";
                LogType = "内容变更";
            }
            if (data["Department"] != NodeObjBefore.Department) {
                TempStr += "变更部门为：" + data["Department"] + "；";
                LogType = "内容变更";
            }
            if (data["UserId"] != NodeObjBefore.UserId) {
                TempStr += "变更负责人为：" + data["UserName"] + "；";
                LogType = "内容变更";
            }
            //以下为状态变更
            if (data["NodeState"] != NodeObjBefore.NodeState) {
                TempStr += "变更状态为：" + data["NodeState"] + "；";
                LogType = "状态变更";
            }


            //添加日志记录
            if (LogType != "") {//如果LogType有变化，则表明有变更
                $.post("/Process/ProcessLogTextAdd", { "ProcessId": data["ProcessId"], "LogContent": TempStr, "LogType": LogType },
                    function (msg) {
                        if (msg.result == "OK") {
                        } else {
                            alert(msg.result);
                        }
                    });
            }

            //变更申请状态
            if (LogType == "状态变更" && (data["NodeState"] == "进行中" || data["NodeState"] == "滞后") ) {
                $.post("/Process/ProcessAppState", { "ProcessId": data["ProcessId"], "Value": 0 },
                    function (msg) {
                        if (msg.result == "OK") {

                        } else {
                            alert(msg.result);
                            return;
                        }
                    });
            }
            else if (LogType == "状态变更" && data["NodeState"] == "已完成") {
                $.post("/Process/ProcessAppState", { "ProcessId": data["ProcessId"], "Value": 2 },
                    function (msg) {
                        if (msg.result == "OK") {

                        } else {
                            alert(msg.result);
                            return;
                        }
                    });
            }



            $.ajax({
                type: "POST",
                url: "/Process/ProcessEditUpdate",
                async: false,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(data),
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('修改成功', { icon: 6, time: 1000 });
                        layer.close(layerindex);
                        ReflushContent(ProjectId, StateSel);
                    } else {
                        alert(msg.result);
                    }
                }
            });


        });

        $("#BtnEditFromDel").on("click", function () {
            //先判断权限 节点管理
            if (false == SearchAuth("ProcessAuth", "节点管理")) {
                alert("没有权限");
                return;
            }
            var TempName = $("#EditFrom input[name='NodeName']").val();
            var TempProcessId = $("#EditFrom input[name='ProcessId']").val();
            layer.confirm('确实删除节点：' + TempName, { icon: 3, title: '提示' }, function (index) {
                //do something
                $.ajax({
                    type: "POST",
                    url: "/Process/ProcessEditDel",
                    async: false,
                    data: { "ProcessId": TempProcessId },
                    success: function (msg) {
                        if (msg.result == "OK") {
                            parent.layer.msg('删除成功', { icon: 6, time: 1000 });
                            layer.close(layerindex);
                            ReflushContent(ProjectId, StateSel);
                        } else {
                            alert(msg.result);
                        }
                    }
                });
                layer.close(index);
            });
        });

        /////////////////////////////////////////////////////////////////////////////
        //引入模板
        table.render({
            elem: '#QuoteTable'
            , method: 'post'
            //, height: 315
            , url: '/Process/ProcessQuoteTableRequest' //数据接口
            , page: true //开启分页
            , where: { SortName: "TempName", Order: "Desc", Condition: " and 1=1 group by TempName" }
            , limits: [50, 100, 200]
            , cols: [[ //表头
                { type: 'radio' }
                , { field: 'TempName', title: '模板名称', width: 250 }
            ]]
        });


        $("#BtnQuoteSave").on("click", function () {
            var StartTime = $("#TemplateStartTime").val();
            var EndTime = $("#TemplateEndTime").val();
            //tempname = tempname.replace(/\s*/g, "");
            if (StartTime == "" || EndTime == "") {
                return;
            }
            if (StartTime > EndTime) { alert("请输入正确日期"); return; }
            var checkStatus = table.checkStatus('QuoteTable');
            var data = checkStatus.data;    //这里得到的data是array类型
            if (data.length != 1) {
                layer.msg('请选中一行', { icon: 3, time: 1000 });
                return;
            }

            $.ajax({
                type: "POST",
                url: "/Process/ProcessQuoteAdd",
                async: false,
                data: { "TempName": data[0].TempName, "ProjectId": ProjectId, "StartTime": StartTime, "EndTime": EndTime },
                success: function (msg) {
                    if (msg.result == "OK") {
                        layer.msg('添加成功"', { icon: 6, time: 1000 });
                        ReflushContent(ProjectId, StateSel);
                        layer.close(layerindex);
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });


        $("#BtnOpenLogLayer").on("click", function () {
            layerindex_Log = layer.open({
                type: 1,
                title: ['新增记录', 'font-size:18px;'],
                area: ['600px', '300px'],
                content: $("#LogAddLayer"),  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                success: function (layero, index) {

                    //$("#AddFrom input[name='TestFeeId']").val("");
                    //$("#Type").find("option[value='" + TypeName + "']").attr("selected", true);
                    //form.render();
                }
            });
        });



        //添加日志文字描述记录
        $("#BtnLogTextAdd").on("click", function () {
            var temptext = "";
            temptext = $("#LogTextarea").val();
            if (temptext == "" || temptext == null) {
                return;
            }
            var ProcessId = $("#EditFrom input[name='ProcessId']").val();
            $.ajax({
                type: "POST",
                url: "/Process/ProcessLogTextAdd",
                async: false,
                data: { "ProcessId": ProcessId, "LogContent": temptext, "LogType":"添加记录" },
                success: function (msg) {
                    if (msg.result == "OK") {
                        parent.layer.msg('添加成功', { icon: 6, time: 1000 });
                        layer.close(layerindex_Log);
                        $("#LogTextarea").val("");
                        ReflushLog(ProcessId);
                        //ReflushContent(ProjectId, StateSel);
                    } else {
                        alert(msg.result);
                    }
                }
            });
        });

        //申请完结
        $("#BtnRequestDone").on("click", function () {
            var CurrText= $("#BtnRequestDone").text();
            if (CurrText == "驳回申请") {
                if (false == SearchAuth("ProcessAuth", NodeObjBefore.Department)) {
                    alert("没有权限");
                    return;
                }
            }
            else {
                if (UserId != NodeObjBefore.UserId) {
                    alert("没有权限");
                    return;
                }
            }

            var ProcessId = $("#EditFrom input[name='ProcessId']").val();
            if (ApplicationState == 1) {
                //这里文本已经变为驳回申请，再次点击就会驳回
                //这里需要判断权限，
                $.post("/Process/ProcessAppState", { "ProcessId": ProcessId, "Value": 0 },
                    function (msg) {
                        if (msg.result == "OK") {
                            layer.msg('驳回成功', { icon: 6, time: 1000 });
                            ReflushContent(ProjectId, StateSel);
                            layer.close(layerindex);
                        } else {
                            alert(msg.result);
                        }
                    });
            }
            else {
                if (ApplicationState == 2) return;//这里表示节点已经完成

                //这里表示正常申请申请
                $.post("/Process/ProcessAppState", { "ProcessId": ProcessId,"Value":1 },
                    function (msg) {
                        if (msg.result == "OK") {
                            layer.msg('申请成功', { icon: 6, time: 1000 });
                            ReflushContent(ProjectId, StateSel);
                            layer.close(layerindex);
                        } else {
                            alert(msg.result);
                        }
                    });
            }


        });



    });

    function ReflushLog(ProcessId) {
        //alert(ProcessId);
        $.ajax({
            type: "POST",
            url: "/Process/ProcessGetLog",
            async: false,
            data: { "ProcessId": ProcessId},
            success: function (msg) {
                $("#LogContent").empty();
                var str = "";
                for (var i = 0; i < msg.length; i++) {
                    str = "<div>" +
                        '<div style="margin-left:10px;"><span style="margin-right:10px;">' + msg[i].LogType + '</span>执行人"' + msg[i].UserName+'":'+msg[i].LogTime+'</div>' +
                        '<blockquote class="layui-elem-quote" style="padding:5px;">'+msg[i].LogContent+'</blockquote>' +
                        '</div>';
                    $("#LogContent").append(str);

                }


            }
        });
    }

    function ProStageTrans(ProStage) {
        switch (ProStage) {
            case 1:
                return "项目前期";
                break;
            case 2:
                return "前期测算";
                break;
            case 3:
                return "项目实施";
                break;
            case 4:
                return "竣工结算";
                break;
            case 5:
                return "决算收款";
                break;
            default:
                "ERROR";
                break;
        }
    }


</script>

